#include <stdio.h>
#include <string.h>


int n;

char ss[65][85];
int count[150][150];
double tot;
main()
{
	int i,j,k,len,max;
	char a,b;
	while (1)
	{
		scanf("%d", &n);
		if (n==0) break;
		memset(ss,0,sizeof(ss));
		memset(count,0,sizeof(count));
		tot=0;
		for (i=1;i<=n;i++)
		{
			gets(ss[i]);
			if (strlen(ss[i])==0) gets(ss[i]);
		}
		for (i=1;i<=n;i++)
		{
			len=strlen(ss[i]);
			tot=tot+len;
			for (j=1;j<len;j++)
			{
				a=ss[i][j-1];
				b=ss[i][j];
				count[a][b]++;
			}
		}
		for (i=1;i<n;i++)
		{
			j=strlen(ss[i]);
			a=ss[i][j-1];
			b=ss[i+1][0];
			count[a][b]++;
		}
		tot=tot-1;
		for (k=1;k<=5;k++)
		{
			max=0;
			a=1;b=1;
			for (i=1;i<=140;i++)
				for (j=1;j<=140;j++)
					if (count[i][j]>max)
					{
						max=count[i][j];
						a=i;
						b=j;
					}
			count[a][b]=0;
			printf("%c%c %d %.6lf\n", a,b,max,max/tot);	
			
		}
		
		



		printf("\n");
	}
	

	return 0;
}
